package com.luanye.enjoy.controller;


import com.luanye.enjoy.enums.ResultCode;
import com.luanye.enjoy.service.WikipediaService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;

@RestController
@RequestMapping("/article")
@AllArgsConstructor
public class WikipediaController {

    private final WikipediaService wikipediaService;

    @GetMapping("/{modeId}/{typeId}/{pageNum}/{limit}")
    public RespBean getWikiList(@PathVariable("pageNum") Integer pageNum,
                                @PathVariable("limit") Integer limit,
                                @PathVariable("typeId") Integer typeId,
                                @PathVariable("modeId") Integer modeId){
        if (Objects.isNull(pageNum) || Objects.isNull(limit) || Objects.isNull(typeId)
                || Objects.isNull(modeId))
            return RespBean.error(ResultCode.VALIDATE_ERROR);

        return wikipediaService.getWikiList(pageNum,limit,typeId,modeId);
    }
    @GetMapping("/getDetail/{articleId}")
    public RespBean getArticleDetail(@PathVariable("articleId") Long articleId){
        if (Objects.isNull(articleId))
            return RespBean.error(ResultCode.VALIDATE_ERROR);
        return wikipediaService.getArticleById(articleId);
    }
}
